package com.radiant.data.entity;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import com.radiant.data.annotation.Entity;
import com.radiant.data.annotation.Persist;

@XmlRootElement
@Entity(name="Comment")
public class Comment implements ActivityFeedable {

	@Persist(name="commentId",itemName=true)
	private String commentId;

	@XmlTransient
	@Persist(name="post")	
	private Post post;

	@Persist(name="userName")	
	private String from;
	
	@Persist(name="message")	
	private String message;

	@Persist(name="timeCreated")	
	private Date timeCreated;

	@Persist(name="likes", multiValue=true, multiValueType=Like.class)	
	private List<Like> likes = new ArrayList<Like>();

	public Comment() {
		this(false);
	}

	public Comment(boolean generateId) {
		super();
		commentId = UUID.randomUUID().toString();
	}

	public String getCommentId() {
		return commentId;
	}

	public void setCommentId(String commentId) {
		this.commentId = commentId;
	}
	
	public String getFrom() {
		return from;
	}
	
	public void setFrom(String from) {
		this.from = from;
	}
	
	public String getMessage() {
		return message;
	}
	
	public void setMessage(String message) {
		this.message = message;
	}
	
	public Date getTimeCreated() {
		return timeCreated;
	}
	
	public void setTimeCreated(Date timeCreated) {
		this.timeCreated = timeCreated;
	}

	public Post getPost() {
		return post;
	}

	public void setPost(Post post) {
		this.post = post;
	}

	public List<Like> getLikes() {
		return likes;
	}
	public void setLikes(List<Like> likes) {
		this.likes = likes;
	}
	
	public void addToActivity(Activity activity) {
		activity.setPost(post);
	}

	public void addMessageToActivity(Activity activity, User creator, Child child) {
		StringBuffer sb = new StringBuffer();
		sb.append(creator.getUserName()).append("commented on ");
		sb.append("post owner's").append("post");
		activity.setMessage(sb.toString());
	}

}
